package com.fingard.dsp.bank.directbank.cmb01;

import com.fingard.constant.Format;
import com.fingard.diagnostics.LogHelper;
import com.fingard.dsp.bank.directbank.bankInterface.IQryRefund;
import com.fingard.dsp.bank.helpers.SeqRefundInfo;
import com.fingard.dsp.bank.helpers.SeqRefundInfoHelper;
import com.fingard.dsp.bank.reqrespobj.qryrefund.ReqQryRefund;
import com.fingard.dsp.bank.reqrespobj.qryrefund.RetAtsQryRefund;
import com.fingard.dsp.bank.reqrespobj.qryrefund.detail.RetAtsRefundDetail;
import com.fingard.text.StringHelper;
import com.fingard.util.DateHelper;
import com.fingard.xml.XmlTextReader;
import com.fingard.xml.XmlTextWriter;

import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;

public class CMB01QryRefund extends CMB01Base implements IQryRefund {
    @Override
    public RetAtsQryRefund d_qry_refund(ReqQryRefund p_req) throws Exception {
        String isSetSleep = getBankConfig().getValueAsString("useSleepGetQuery");
        if ("true".equals(isSetSleep.toLowerCase())) {
            int realSleepTime = getBankConfig().getValueAsInt("QuerySleepTime");
            if (realSleepTime > 0) {
                Date lastSleepGetQuery;
                String keyLastSleep = "lastSleepGetQueryQryRefund";
                synchronized (bankFront.mutexQryRefund) {
                    if (this.bankFront.customObjects.containsKey(keyLastSleep)) {
                        lastSleepGetQuery = (Date) bankFront.customObjects.get(keyLastSleep);
                        long diffMil = DateHelper.getDifferMilSecs(new Date(), lastSleepGetQuery);
                        long needSlpMil = realSleepTime * 1000;
                        long slpMil = needSlpMil - diffMil;
                        if (slpMil > 0) {
                            this.WriteBankLogLn("等待" + slpMil + "毫秒");
                            Thread.sleep(slpMil);
                        }
                        bankFront.putCustomObjects(keyLastSleep, new Date());
                    } else {
                        bankFront.putCustomObjects(keyLastSleep, new Date());
                    }
                }
            }
        }

        RetAtsQryRefund retAts = new RetAtsQryRefund(p_req.reqHeader);
        retAts.writeStart();
        if (p_req.isVirtual) {
            if (StringHelper.hasAnyChar(p_req.virtualNo)) {
                return d_qry_newRefund(p_req);
            } else {
                retAts.writeRespCode("0");
                retAts.writeRespInfo("VirtualNo节点中虚拟户编号为空，请检查报文");
                retAts.writeEnd();
                return retAts;
            }
        } else {
            if (getBankConfig().getValueAsBool("useNewQryRefund")) {
                return d_newQryRefund(p_req);
            } else {
                return d_qry_oldRefund(p_req);
            }
        }
    }

    public RetAtsQryRefund d_qry_oldRefund(ReqQryRefund p_req) throws Exception {
        RetAtsQryRefund retAts = new RetAtsQryRefund(p_req.reqHeader);
        retAts.writeStart();
        String tmpRespCode = "";
        String tmpRespInfo = "";

        int tmpSuccCount = 0;
        BigDecimal tmpTotalAmt = new BigDecimal("0");

        SeqRefundInfoHelper seqRefundHelper = null;
        try {
            seqRefundHelper = new SeqRefundInfoHelper(p_req.reqHeader.tenant, p_req.reqHeader.getBusTime(new Date()));
            SeqRefundInfo refundInfo = new SeqRefundInfo();
            refundInfo.loadFromReqBat(p_req);
            Calendar tmpCalendarFrom = Calendar.getInstance();
            tmpCalendarFrom.setTime(p_req.getQryStartDate());

            Calendar tmpCalendarTo = Calendar.getInstance();
            tmpCalendarTo.setTime(p_req.getQryEndDate());
            tmpCalendarTo.add(Calendar.DAY_OF_MONTH, 1);

            while (tmpCalendarFrom.compareTo(tmpCalendarTo) == -1) {
                CMB01Header tmpBnkHeader = new CMB01Header();
                tmpBnkHeader.FUNNAM = "GetPaymentInfo";

                XmlTextWriter xmlWriter = new XmlTextWriter();
                writeCommonHeader(xmlWriter, tmpBnkHeader);

                xmlWriter.writeStartElement("SDKPAYQYX");
                xmlWriter.writeElementClosed("BUSCOD");
                Date tmpQryDate = tmpCalendarFrom.getTime();
                xmlWriter.writeElementString("BGNDAT", Format.Date8Format.format(tmpQryDate));
                xmlWriter.writeElementString("ENDDAT", Format.Date8Format.format(tmpQryDate));
                xmlWriter.writeElementString("RTNFLG", "B"); /* B:退票 */
                xmlWriter.writeEndDocument();

                String[] tmpRetBkStr = sendToBank(xmlWriter.toXmlString());

                if (tmpRetBkStr[0].length() == 0) {
                    StringBuilder tmpSbMsg = new StringBuilder();
                    XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpRetBkStr[1], tmpSbMsg);

                    if (tmpBkReader != null) {
                        String tmpRetCode = tmpBkReader.getFirstText("/CMBSDKPGK/INFO/RETCOD");
                        String tmpRetMsg = tmpBkReader.getFirstText("/CMBSDKPGK/INFO/ERRMSG");

                        if (tmpRetCode != null && tmpRetCode.equals("0")) {
                            while (tmpBkReader.read("/CMBSDKPGK/NTQPAYQYZ")) {
                                if (!"B".equals(tmpBkReader.readedXElement.getSingleText("RTNFLG"))) {
                                    continue;
                                }

                                RetAtsRefundDetail tmpRetDetail = new RetAtsRefundDetail();

                                tmpRetDetail.askNum = tmpBkReader.readedXElement.getSingleText("YURREF");
                                refundInfo.askNumber = tmpRetDetail.askNum;
                                tmpRetDetail.payAct = tmpBkReader.readedXElement.getSingleText("DBTACC");
                                tmpRetDetail.payActName = tmpBkReader.readedXElement.getSingleText("DBTNAM");
                                tmpRetDetail.recAct = tmpBkReader.readedXElement.getSingleText("CRTACC");
                                tmpRetDetail.recActName = tmpBkReader.readedXElement.getSingleText("CRTNAM");
                                tmpRetDetail.amount = tmpBkReader.readedXElement.getSingleText("TRSAMT");
                                tmpRetDetail.refundTicketDate = Format.Date10Format.format(tmpCalendarFrom.getTime());
                                tmpRetDetail.submitTime = Format.DateTimeFormat.format(tmpCalendarFrom.getTime());
                                refundInfo.qryEndDate = p_req.getQryEndDate();
                                String refundReason = tmpBkReader.readedXElement.getSingleText("RTNNAR");
                                if (StringHelper.isNullOrEmpty(refundReason)) {
                                    refundReason = tmpBkReader.readedXElement.getSingleText("C_RTNFLG");
                                }
                                tmpRetDetail.refundTicketReason = refundReason;
                                refundInfo.refundTicketReason = refundReason;
                                tmpSuccCount++;
                                tmpTotalAmt = tmpTotalAmt.add(new BigDecimal(tmpRetDetail.amount));
                                try {
                                    seqRefundHelper.insertSeqRefundInfo(refundInfo);
                                } catch (Exception ex) {
                                    this.WriteBankLogLn(ex);
                                    tmpRespInfo = "保存交易信息于DB出现异常，不继续执行报文发送，异常信息：" + LogHelper.getStackTraceFirstLine(ex);
                                    tmpRespCode = "0";
                                    retAts.writeRespCode(tmpRespCode);
                                    retAts.writeRespInfo(tmpRespInfo);
                                    retAts.writeEnd();
                                    return retAts;
                                }
                                retAts.writeRetDetailOnly(tmpRetDetail);
                            }
                        } else {
                            tmpRespCode = "-1";
                            tmpRespInfo = tmpRetMsg;
                        }
                    } else {
                        tmpRespCode = "-1";
                        tmpRespInfo = tmpSbMsg.toString();
                    }
                } else {
                    tmpRespCode = "-1";
                    tmpRespInfo = tmpRetBkStr[1];
                }

                tmpCalendarFrom.add(Calendar.DAY_OF_MONTH, 1);
            }

            retAts.totleAmount = Format.DecimalAmtFormat.format(tmpTotalAmt);
            retAts.totleNum = String.valueOf(tmpSuccCount);
            retAts.writeTotalInfo();
        } catch (Exception ex) {
            tmpRespCode = "-1";
            tmpRespInfo = ex.getMessage();
            WriteBankLogLn(ex);
        } finally {
            if (seqRefundHelper != null) {
                seqRefundHelper.close();
            }
        }

        if (tmpRespCode.equals("-1")) {
            retAts.writeRespCode(tmpRespCode);
            retAts.writeRespInfo(tmpRespInfo);
        } else if (retAts.getWrittenRdCount() == 0) {
            retAts.writeRespCode("0");
            retAts.writeRespInfo("当前时间范围内无退票数据");
        }

        retAts.writeEnd();
        return retAts;
    }

    /**
     * 参考文档：https://u.ebank.cmbchina.com/CmbBank_GenShell/UI/Help/DCBank2/API.aspx?03ZFJS/12NTPAYQYB
     * 参考章节：3.3.支付结果列表查询
     */
    public RetAtsQryRefund d_qry_newRefund(ReqQryRefund p_req) throws Exception {
        RetAtsQryRefund retAts = new RetAtsQryRefund(p_req.reqHeader);
        retAts.writeStart();

        String tmpRespCode = "";
        String tmpRespInfo = "";

        int tmpSuccCount = 0;
        BigDecimal tmpTotalAmt = new BigDecimal("0");

        try {
            Calendar tmpCalendarFrom = Calendar.getInstance();
            tmpCalendarFrom.setTime(p_req.getQryStartDate());

            Calendar tmpCalendarTo = Calendar.getInstance();
            tmpCalendarTo.setTime(p_req.getQryEndDate());
            tmpCalendarTo.add(Calendar.DAY_OF_MONTH, 1);

            while (tmpCalendarFrom.compareTo(tmpCalendarTo) == -1) {
                CMB01Header tmpBnkHeader = new CMB01Header();
                tmpBnkHeader.FUNNAM = "NTQRYSTN";
                XmlTextWriter xmlWriter = new XmlTextWriter();
                writeCommonHeader(xmlWriter, tmpBnkHeader);

                xmlWriter.writeStartElement("NTQRYSTNY1");
                xmlWriter.writeElementString("BUSCOD", "N02031");
                String tmpBUSMOD = getBankConfig().getValueAsString("tmpBUSMOD");
                if (StringHelper.hasAnyChar(tmpBUSMOD)) {
                    xmlWriter.writeElementString("BUSMOD", tmpBUSMOD);
                } else {
                    retAts.writeRespCode("-1");
                    retAts.writeRespInfo("业务模式BUSMOD为空，请检查config.xml中'tmpBUSMOD'配置信息.");
                    retAts.writeEnd();
                    return retAts;
                }
                Date tmpQryDate = tmpCalendarFrom.getTime();
                xmlWriter.writeElementString("BGNDAT", Format.Date8Format.format(tmpQryDate));
                xmlWriter.writeElementString("ENDDAT", Format.Date8Format.format(tmpQryDate));
                xmlWriter.writeElementString("DATFLG", "A");
                xmlWriter.writeElementString("RSV50Z", p_req.virtualNo);
                xmlWriter.writeEndDocument();

                String[] tmpRetBkStr = sendToBank(xmlWriter.toXmlString());

                if (tmpRetBkStr[0].length() == 0) {
                    StringBuilder tmpSbMsg = new StringBuilder();
                    XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpRetBkStr[1], tmpSbMsg);

                    if (tmpBkReader != null) {
                        String tmpRetCode = tmpBkReader.getFirstText("/CMBSDKPGK/INFO/RETCOD");
                        String tmpRetMsg = tmpBkReader.getFirstText("/CMBSDKPGK/INFO/ERRMSG");

                        if (tmpRetCode != null && tmpRetCode.equals("0")) {
                            while (tmpBkReader.read("/CMBSDKPGK/NTSTLLSTZ")) {
                                RetAtsRefundDetail tmpRetDetail = new RetAtsRefundDetail();

                                tmpRetDetail.askNum = tmpBkReader.readedXElement.getSingleText("YURREF");
                                tmpRetDetail.recAct = tmpBkReader.readedXElement.getSingleText("CRTACC");
                                tmpRetDetail.recActName = tmpBkReader.readedXElement.getSingleText("CRTNAM");
                                tmpRetDetail.amount = tmpBkReader.readedXElement.getSingleText("TRSAMT");
                                tmpRetDetail.refundTicketDate = Format.Date10Format.format(tmpCalendarFrom.getTime());
                                tmpRetDetail.submitTime = Format.DateTimeFormat.format(tmpCalendarFrom.getTime());

                                String refundReason = tmpBkReader.readedXElement.getSingleText("RTNFLG");
                                if (StringHelper.isNullOrEmpty(refundReason)) {
                                    refundReason = tmpBkReader.readedXElement.getSingleText("ATHFLG");
                                }
                                tmpRetDetail.refundTicketReason = refundReason;

                                tmpSuccCount++;
                                tmpTotalAmt = tmpTotalAmt.add(new BigDecimal(tmpRetDetail.amount));

                                retAts.writeRetDetailOnly(tmpRetDetail);
                            }
                        } else {
                            tmpRespCode = "-1";
                            tmpRespInfo = tmpRetMsg;
                        }
                    } else {
                        tmpRespCode = "-1";
                        tmpRespInfo = tmpSbMsg.toString();
                    }
                } else {
                    tmpRespCode = "-1";
                    tmpRespInfo = tmpRetBkStr[1];
                }

                tmpCalendarFrom.add(Calendar.DAY_OF_MONTH, 1);
            }

            retAts.totleAmount = Format.DecimalAmtFormat.format(tmpTotalAmt);
            retAts.totleNum = String.valueOf(tmpSuccCount);
            retAts.writeTotalInfo();
        } catch (Exception ex) {
            ex.printStackTrace();
            tmpRespCode = "-1";
            tmpRespInfo = ex.getMessage();
            WriteBankLogLn(ex);
        }

        if (tmpRespCode.equals("-1")) {
            retAts.writeRespCode(tmpRespCode);
            retAts.writeRespInfo(tmpRespInfo);
        } else if (retAts.getWrittenRdCount() == 0) {
            retAts.writeRespCode("0");
            retAts.writeRespInfo("当前时间范围内无退票数据");
        }

        retAts.writeEnd();
        return retAts;
    }

    public RetAtsQryRefund d_newQryRefund(ReqQryRefund p_req) throws Exception {
        RetAtsQryRefund retAts = new RetAtsQryRefund(p_req.reqHeader);
        retAts.writeStart();

        String[] tmpNTPAYQYBRespHeader = getRefundByNTPAYQYB(p_req, retAts);
        String tmpNTPAYQYBTotalNum = retAts.totleNum;
        String tmpNTPAYQYBTotalAmt = retAts.totleAmount;

        String[] tmpNTAGDRFDRespHeader = getRefundByNTAGDRFD(p_req, retAts);
        String tmpNTAGDRFDTotalNum = retAts.totleNum;
        String tmpNTAGDRFDTotalAmt = retAts.totleAmount;

        if ("-1".equals(tmpNTPAYQYBRespHeader[0]) && "-1".equals(tmpNTAGDRFDRespHeader[0])) {
            retAts.writeRespCode("-1");
            retAts.writeRespInfo("支付退票明细查询失败,原因:" + tmpNTPAYQYBRespHeader[1] + ",代发退票明细查询失败,原因:" + tmpNTAGDRFDRespHeader[1]);
        } else {
            if (retAts.getWrittenRdCount() == 0) {
                retAts.writeRespCode("0");
                String respInfo = tmpNTPAYQYBRespHeader[1];
                if (StringHelper.isNullOrEmpty(respInfo)) {
                    respInfo = "当前时间范围内无退票数据";
                }
                retAts.writeRespInfo(respInfo);
            } else {
                retAts.totleNum = String.valueOf(Integer.parseInt(tmpNTPAYQYBTotalNum) + Integer.parseInt(tmpNTAGDRFDTotalNum));
                retAts.totleAmount = String.valueOf(Double.parseDouble(tmpNTPAYQYBTotalAmt) + Double.parseDouble(tmpNTAGDRFDTotalAmt));
                retAts.writeTotalInfo();
            }
        }

        retAts.writeEnd();
        return retAts;
    }

    /**
     * 参考文档：https://u.ebank.cmbchina.com/CmbBank_GenShell/UI/Help/DCBank2/API.aspx?03ZFJS/12NTPAYQYB
     * 参考章节：3.12.支付退票明细查询
     */
    public String[] getRefundByNTPAYQYB(ReqQryRefund p_req, RetAtsQryRefund retAts) throws Exception {
        String[] respHeader = new String[]{"", ""};

        String tmpRespCode = "";
        String tmpRespInfo = "";

        retAts.totleNum = "0";
        retAts.totleAmount = "0";
        int tmpSuccCount = 0;
        BigDecimal tmpTotalAmt = new BigDecimal("0");

        try {
            Calendar tmpCalendarFrom = Calendar.getInstance();
            tmpCalendarFrom.setTime(p_req.getQryStartDate());

            Calendar tmpCalendarTo = Calendar.getInstance();
            tmpCalendarTo.setTime(p_req.getQryEndDate());
            tmpCalendarTo.add(Calendar.DAY_OF_MONTH, 1);

            while (tmpCalendarFrom.compareTo(tmpCalendarTo) == -1) {
                CMB01Header tmpBnkHeader = new CMB01Header();
                tmpBnkHeader.FUNNAM = "NTPAYQYB";

                XmlTextWriter xmlWriter = new XmlTextWriter();
                writeCommonHeader(xmlWriter, tmpBnkHeader);

                xmlWriter.writeStartElement("NTPAYQYBY1");
                xmlWriter.writeElementString("BBKNBR", p_req.areaCode);
                xmlWriter.writeElementString("ACCNBR", p_req.payAct);
                Date tmpQryDate = tmpCalendarFrom.getTime();
                xmlWriter.writeElementString("BGNDAT", Format.Date8Format.format(tmpQryDate));
                xmlWriter.writeElementString("ENDDAT", Format.Date8Format.format(tmpQryDate));
                xmlWriter.writeElementClosed("REQNBR");
                xmlWriter.writeEndDocument();

                String[] tmpRetBkStr = sendToBank(xmlWriter.toXmlString());

                if (tmpRetBkStr[0].length() == 0) {
                    StringBuilder tmpSbMsg = new StringBuilder();
                    XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpRetBkStr[1], tmpSbMsg);

                    if (tmpBkReader != null) {
                        String tmpRetCode = tmpBkReader.getFirstText("/CMBSDKPGK/INFO/RETCOD");
                        String tmpRetMsg = tmpBkReader.getFirstText("/CMBSDKPGK/INFO/ERRMSG");

                        if (tmpRetCode != null && tmpRetCode.equals("0")) {
                            while (tmpBkReader.read("/CMBSDKPGK/NTPAYQYBZ1")) {

                                RetAtsRefundDetail tmpRetDetail = new RetAtsRefundDetail();

                                tmpRetDetail.askNum = tmpBkReader.readedXElement.getSingleText("YURREF");
                                tmpRetDetail.payAct = tmpBkReader.readedXElement.getSingleText("SNDEAC");
                                tmpRetDetail.payActName = tmpBkReader.readedXElement.getSingleText("SNDEAN");
                                tmpRetDetail.recAct = tmpBkReader.readedXElement.getSingleText("RCVEAC");
                                tmpRetDetail.recActName = tmpBkReader.readedXElement.getSingleText("RCVEAN");
                                tmpRetDetail.amount = tmpBkReader.readedXElement.getSingleText("TRSAMT");
                                tmpRetDetail.refundTicketDate = Format.Date10Format.format(Format.Date8Format.parse(tmpBkReader.readedXElement.getSingleText("UPDDAT")));
                                tmpRetDetail.submitTime = Format.DateTimeFormat.format(Format.Date8Format.parse(tmpBkReader.readedXElement.getSingleText("ISUDAT")));
                                tmpRetDetail.refundTicketReason = tmpBkReader.readedXElement.getSingleText("WATRCN");

                                tmpSuccCount++;
                                tmpTotalAmt = tmpTotalAmt.add(new BigDecimal(tmpRetDetail.amount));

                                retAts.writeRetDetailOnly(tmpRetDetail);
                            }
                        } else {
                            tmpRespCode = "-1";
                            tmpRespInfo = tmpRetMsg;
                        }
                    } else {
                        tmpRespCode = "-1";
                        tmpRespInfo = tmpSbMsg.toString();
                    }
                } else {
                    tmpRespCode = "-1";
                    tmpRespInfo = tmpRetBkStr[1];
                }

                tmpCalendarFrom.add(Calendar.DAY_OF_MONTH, 1);
            }

        } catch (Exception ex) {
            tmpRespCode = "-1";
            tmpRespInfo = ex.getMessage();
            WriteBankLogLn(ex);
        }

        retAts.totleAmount = Format.DecimalAmtFormat.format(tmpTotalAmt);
        retAts.totleNum = String.valueOf(tmpSuccCount);

        respHeader[0] = tmpRespCode;
        respHeader[1] = tmpRespInfo;

        return respHeader;
    }

    /**
     * 参考文档：https://u.ebank.cmbchina.com/CmbBank_GenShell/UI/Help/DCBank2/API.aspx?04DFDK/12NTAGDRFD
     * 参考章节：4.12.代发退票明细查询
     */
    public String[] getRefundByNTAGDRFD(ReqQryRefund p_req, RetAtsQryRefund retAts) throws Exception {
        String[] respHeader = new String[]{"", ""};

        String tmpRespCode = "";
        String tmpRespInfo = "";

        retAts.totleNum = "0";
        retAts.totleAmount = "0";
        int tmpSuccCount = 0;
        BigDecimal tmpTotalAmt = new BigDecimal("0");

        try {
            Calendar tmpCalendarFrom = Calendar.getInstance();
            tmpCalendarFrom.setTime(p_req.getQryStartDate());

            Calendar tmpCalendarTo = Calendar.getInstance();
            tmpCalendarTo.setTime(p_req.getQryEndDate());
            tmpCalendarTo.add(Calendar.DAY_OF_MONTH, 1);

            while (tmpCalendarFrom.compareTo(tmpCalendarTo) == -1) {
                CMB01Header tmpBnkHeader = new CMB01Header();
                tmpBnkHeader.FUNNAM = "NTAGDRFD";

                XmlTextWriter xmlWriter = new XmlTextWriter();
                writeCommonHeader(xmlWriter, tmpBnkHeader);

                xmlWriter.writeStartElement("NTAGDRFDY1");
                xmlWriter.writeElementString("BBKNBR", p_req.areaCode);
                xmlWriter.writeElementString("ACCNBR", p_req.payAct);
                xmlWriter.writeElementString("TRSTYP", "BYBK");
                Date tmpQryDate = tmpCalendarFrom.getTime();
                xmlWriter.writeElementString("BGNDAT", Format.Date8Format.format(tmpQryDate));
                xmlWriter.writeElementString("ENDDAT", Format.Date8Format.format(tmpQryDate));
                xmlWriter.writeElementClosed("REQNBR");
                xmlWriter.writeEndDocument();

                String[] tmpRetBkStr = sendToBank(xmlWriter.toXmlString());

                if (tmpRetBkStr[0].length() == 0) {
                    StringBuilder tmpSbMsg = new StringBuilder();
                    XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpRetBkStr[1], tmpSbMsg);

                    if (tmpBkReader != null) {
                        String tmpRetCode = tmpBkReader.getFirstText("/CMBSDKPGK/INFO/RETCOD");
                        String tmpRetMsg = tmpBkReader.getFirstText("/CMBSDKPGK/INFO/ERRMSG");

                        if (tmpRetCode != null && tmpRetCode.equals("0")) {
                            while (tmpBkReader.read("/CMBSDKPGK/NTAGDRFDZ1")) {

                                RetAtsRefundDetail tmpRetDetail = new RetAtsRefundDetail();

                                tmpRetDetail.askNum = tmpBkReader.readedXElement.getSingleText("YURREF");
                                tmpRetDetail.payAct = tmpBkReader.readedXElement.getSingleText("CPRACT");
                                tmpRetDetail.payActName = p_req.payActName;
                                tmpRetDetail.recAct = tmpBkReader.readedXElement.getSingleText("EACNBR");
                                tmpRetDetail.recActName = tmpBkReader.readedXElement.getSingleText("EACNAM");
                                tmpRetDetail.amount = tmpBkReader.readedXElement.getSingleText("TRSAMT");
                                tmpRetDetail.refundTicketDate = Format.Date10Format.format(Format.Date8Format.parse(tmpBkReader.readedXElement.getSingleText("TRSDAT")));
                                tmpRetDetail.submitTime = Format.DateTimeFormat.format(Format.Date8Format.parse(tmpBkReader.readedXElement.getSingleText("TRSDAT")));
                                tmpRetDetail.refundTicketReason = tmpBkReader.readedXElement.getSingleText("RTNTXT");

                                tmpSuccCount++;
                                tmpTotalAmt = tmpTotalAmt.add(new BigDecimal(tmpRetDetail.amount));

                                retAts.writeRetDetailOnly(tmpRetDetail);
                            }
                        } else {
                            tmpRespCode = "-1";
                            tmpRespInfo = tmpRetMsg;
                        }
                    } else {
                        tmpRespCode = "-1";
                        tmpRespInfo = tmpSbMsg.toString();
                    }
                } else {
                    tmpRespCode = "-1";
                    tmpRespInfo = tmpRetBkStr[1];
                }

                tmpCalendarFrom.add(Calendar.DAY_OF_MONTH, 1);
            }


        } catch (Exception ex) {
            tmpRespCode = "-1";
            tmpRespInfo = ex.getMessage();
            WriteBankLogLn(ex);
        }

        retAts.totleAmount = Format.DecimalAmtFormat.format(tmpTotalAmt);
        retAts.totleNum = String.valueOf(tmpSuccCount);

        respHeader[0] = tmpRespCode;
        respHeader[1] = tmpRespInfo;

        return respHeader;
    }
}

